#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Converting sizes
'''

import os, sys

print("Python version: " + sys.version)
print(__doc__)

SKINS = ('holoFHD-light.GP/skin.xml',)

for skin_file in SKINS:
    print(skin_file)
    skin_main = open(skin_file, 'rb').readlines()
    skin_new = open(skin_file + ".resized.xml", 'wb')
    for index, line in enumerate(skin_main):
        replace = []
        for param in line.split():
            if param.startswith('itemHeight="'):
                print str.format("Line %d: %s" % (index + 1, param))
                s = param.split('"')
                value = param.split('"')[1]
                replace.append((param, str.format('itemHeight="%d"' % (int(float(value) * 1.5)))))
            if param.startswith('font="'):
                print str.format("Line %d: %s" % (index + 1, param))
                f = param.split(';')
                value = f[1][:-1].strip()
                replace.append((param, str.format('%s;%d"' % (f[0], int(float(value) * 1.5)))))
            if param.startswith('position="'):
                print str.format("Line %d: %s" % (index + 1, param))
                f = param[10:param.rfind('"')].split(',')
                x = f[0].isdigit() and int(float(f[0]) * 1.5) or f[0]
                y = f[1].isdigit() and int(float(f[1]) * 1.5) or f[1]
                replace.append((param, str.format('position="%s,%s"' % (x, y))))
            if param.startswith('size="'):
                print str.format("Line %d: %s" % (index + 1, param))
                f = param[6:param.rfind('"')].split(',')
                x = f[0].isdigit() and int(float(f[0]) * 1.5) or f[0]
                y = f[1].isdigit() and int(float(f[1]) * 1.5) or f[1]
                replace.append((param, str.format('size="%s,%s"' % (x, y))))
        for org, new in replace:
            line = line.replace(org, new)
        skin_new.write(line)
    print(skin_file)
    print("Finished")
    skin_new.close()
